{template '_header'}
<div class="page-heading">
    <span class='pull-right'>
        {if $isManager}
        	<a class='btn btn-primary btn-sm' href="{php echo webUrl('sns/posts/add')}"><i class='fa fa-plus'></i> 发表话题</a>
        {/if}
        {ifp 'sns.posts.add'}
        	<a class='btn btn-primary btn-sm' href="{php echo webUrl('sns/board/add')}"><i class='fa fa-plus'></i> 添加版块</a>
        {/if}
        <a class="btn btn-default  btn-sm" href="{php echo webUrl('sns/posts')}">返回列表</a>
    </span>
    <h2>{if !empty($item['id'])}编辑{else}添加{/if}话题 <small>{if !empty($item['id'])}修改【{$item['title']}】{/if}</small></h2>
</div>


<form {ife 'sns.posts' $item}action="" method="post"{/if} class="form-horizontal form-validate" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$item['id']}" />
        <div class="tab-content ">
            <div class="tab-pane active">
                <div class="panel-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label must">版块</label>
                        <div class="col-sm-9 col-xs-12">

                            {ife 'sns.posts' $item}
                            <select name='bid' class='form-control' data-rule-required="true">
                                <option value=""  {if $item['bid']==''}selected{/if}>--请选择版块--</option>
                                {loop $board $c}
                                <option value="{$c['id']}" {if $c['id']==$item['bid']}selected{/if}>{$c['title']}</option>
                                {/loop}
                            </select>
                            {else}
                            <div class='form-control-static'>

                                {loop $board $c}
                                {if $c['id']==$item['bid']}{$c['title']}{/if}
                                {/loop}
                            </div>

                            {/if}
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label must">话题标题</label>
                        <div class="col-sm-9 col-xs-12 ">
                            {ife 'sns.posts' $item}
                            <input type="text" id='title' name="title" class="form-control" value="{$item['title']}" data-rule-required="true"/>
                            {else}
                            <div class='form-control-static'>{$item['title']}</div>
                            {/if}
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label must">发帖管理员</label>
                        <div class="col-sm-9 col-xs-12">
                            {ife 'sns.posts' $item}
                            <select name='openid' class='form-control' data-rule-required="true">
                                <option value=""  {if $item['openid']==''}selected{/if}>--请选择管理员--</option>
                                {loop $managers $c}
                                <option value="{$c['openid']}" {if $c['openid']==$item['openid']}selected{/if}>{$c['nickname']}</option>
                                {/loop}
                            </select>
                            {else}
                            <div class='form-control-static'>
                                {loop $managers $c}
                                {if $c['openid']==$item['openid']}{$c['nickname']}{/if}
                                {/loop}
                            </div>

                            {/if}
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">上传图片</label>
                        <div class="col-sm-9 col-xs-12 gimgs">
                            {ife 'sns.posts' $item}
                            {php echo tpl_form_field_multi_image('images',$piclist)}
                            <span class="help-block image-block" style="display: block;">建议为正方型图片，并保持图片大小一致</span>
                            <span class="help-block">您可以拖动图片改变其显示顺序 </span>
                            {else}
                            {loop $piclist $p}
                            <a href='{php echo tomedia($p)}' target='_blank'>
                                <img src="{php echo tomedia($p)}" style='height:100px;border:1px solid #ccc;padding:1px;float:left;margin-right:5px;' />
                            </a>
                            {/loop}
                            {/if}
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">话题内容</label>
                        <div class="col-sm-9 col-xs-12">
                            {ife 'sns.posts' $item}
                            {php echo tpl_ueditor('content',$item['content'],array('height'=>'200'))}
                            {else}
                            <textarea id='detail' name='content' style='display:none;'>{$item['content']}</textarea>
                            <a href="javascript:preview_html('#detail')" class="btn btn-default">查看内容</a>
                            {/if}
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">其他</label>
                        <div class="col-sm-9 col-xs-12">
                            {ife 'sns.posts' $item}
                            <label class="checkbox-inline">
                                <input type="checkbox" name="isboardbest" value="1" {if !empty($item['isboardbest'])}checked="true"{/if}   /> 板块精华
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" name="isbest" value="1" {if !empty($item['isbest'])}checked="true"{/if}   /> 全站精华
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" name="isboardtop" value="1" {if !empty($item['isboardtop'])}checked="true"{/if}   /> 版块置顶
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" name="istop" value="1" {if !empty($item['istop'])}checked="true"{/if}   /> 全站置顶
                            </label>
                            {else}
                            <div class='form-control-static'>
                                {if !empty($item['isboardbest'])}版块精华{/if}
                                {if !empty($item['isbest'])}全站精华{/if}
                                {if !empty($item['isboardtop'])}版块置顶{/if}
                                {if !empty($item['istop'])}全站置顶{/if}
                            </div>
                            {/if}
                        </div>
                    </div>


                </div>
            </div>

        </div>

{ife 'sns.posts' $item}
<div class="form-group">
    <label class="col-sm-2 control-label"></label>
    <div class="col-sm-9 col-xs-12">
        <input type="submit"  value="提交" class="btn btn-primary" />
    </div>
</div>
{/if}

</form>
<script language='javascript'>
    require(['bootstrap','jquery.ui'], function () {
        $('#myTab a').click(function (e) {
            $('#tab').val($(this).attr('href'));
            e.preventDefault();
            $(this).tab('show');
        })
        $('.multi-img-details').sortable();
    });
    /*var ue = UE.getEditor('content', {
        autoHeight: false,
        wordCount:true,
        maximumWords:1000
    });*/
</script>
{template '_footer'}